package com.iisi.logical;

import java.util.ArrayList;
import java.util.List;

public class Logic {
    final static String fixNum = "%1$05d";

    /**
     * @param args
     */
    public static void main(String[] args) {

        new Logic().exec("F212", 500000);
    }

    public void exec(final String prefix, final int num) {
        List<String> resultList = generatePseudoData(prefix, num);
        Utils.outputFile("d://" + prefix + ".csv", resultList);
    }

    public List<String> generatePseudoData(final String prefix, final int num) {
        List<String> resultList = new ArrayList<String>();
        if (prefix != null && prefix.length() == 4) {
            int count = 0;
            StringBuffer sbf;
            do {
                sbf = new StringBuffer().append(prefix).append(String.format(fixNum, 1 + count));
                String initResult = sbf.toString();
                String zzz = null;
                try {
                    zzz = Utils.getCheckNum(initResult);
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }

                if (validation(initResult) && !zzz.equals("4")) {
                    initResult = initResult + zzz;
                    resultList.add(initResult);
                }
                count++;
            } while (resultList.size() < num);
        }
        return resultList;
    }

    private static boolean validation(final String parameter) {
        boolean result = false;
        char[] parameters = parameter.toCharArray();
        char judgement = '4';
        int count = 0;
        for (char character : parameters) {
            if (character == judgement) {
                count++;
            }
        }
        if (count < 2) {
            result = true;
        }
        return result;
    }

}
